/* Copyright - Apache License 2.0
 * 
 * The project "kyou" is
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.kyou.exception;

import java.io.Serializable;

import net.kyou.data.DataDocument;
import net.kyou.data.dquery.DPath;
import net.kyou.data.dquery.DQuery;
import net.kyou.pack.StyleSpecification;

/**
 * 错误信息条目
 * <p>
 * kyou中所有已知的异常信息都会在此处进行记录，
 * </p>
 * 
 * @author NuclearG (<a href="nuclearg@163.com">nuclearg@163.com</a>)
 */
public final class KyouErr implements Serializable {
    private static final long serialVersionUID = -5501658273930338778L;

    /**
     * 错误的描述
     */
    private final String message;

    /**
     * 初始化一条错误描述信息
     * 
     * @param name
     *            该错误条目的名称
     */
    private KyouErr() {
        this.message = ErrCache.reflectMessage();
    }

    @Override
    public String toString() {
        return this.message;
    }

    /**
     * 内部错误 表示未预料到的错误
     * <p>
     * 程序在运行过程中抛出了未被考虑到的异常 如果产生了该异常，请提交bug
     * </p>
     */
    public static final KyouErr Unknown = new KyouErr();
    /**
     * 内部错误 表示不支持的操作
     * <p>
     * 当前执行的操作不被支持
     * </p>
     */
    public static final KyouErr Unsupported = new KyouErr();
    /**
     * 内部错误 表示未预料到的操作
     * <p>
     * 当前的执行点位于一个未预料的分支中。最典型的情形是程序执行到了一个之前未被考虑到的switch分支中。<br/>
     * 如果产生了该异常，请提交bug
     * </p>
     */
    public static final KyouErr Unexpected = new KyouErr();

    /**
     * 进行一些基础操作时发生的异常
     */
    public static class Base {
        public static final KyouErr UnsupportedCharset = new KyouErr();

        public static final KyouErr NullInputStream = new KyouErr();
        public static final KyouErr NullOutputStream = new KyouErr();
        public static final KyouErr OpenInputStreamFail = new KyouErr();
        public static final KyouErr OpenOutputStreamFail = new KyouErr();
        public static final KyouErr ReadInputStreamFail = new KyouErr();
        public static final KyouErr WriteOutputStreamFail = new KyouErr();
        public static final KyouErr CloseInputStreamFail = new KyouErr();
        public static final KyouErr CloseOutputStreamFail = new KyouErr();

        public static final KyouErr XmlReadFail = new KyouErr();
        public static final KyouErr XmlSaxFail = new KyouErr();
        public static final KyouErr XmlVerifyFail = new KyouErr();
        public static final KyouErr NullXmlNodeToSelect = new KyouErr();
        public static final KyouErr NullXPathToSelect = new KyouErr();
        public static final KyouErr XPathSyntaxError = new KyouErr();

        public static final KyouErr IllegalBackspaceNum = new KyouErr();

        public static final KyouErr StreamNotMarked = new KyouErr();
        public static final KyouErr StreamAlreadyMarked = new KyouErr();
        public static final KyouErr StreamMarkNotFound = new KyouErr();

        public static final KyouErr CompilerInitFail = new KyouErr();
        public static final KyouErr NullCodeToCompile = new KyouErr();
        public static final KyouErr InvaildCodeNameToCompile = new KyouErr();
        public static final KyouErr CompileFail = new KyouErr();
        public static final KyouErr DelegateStaticMethodFail = new KyouErr();
        public static final KyouErr MethodReturnTypeMismatch = new KyouErr();
        public static final KyouErr MethodShouleStatic = new KyouErr();

    }

    /**
     * 进行Schema操作时发生的异常
     */
    public static class Schema {
        public static final KyouErr EmptyAttributeName = new KyouErr();
        public static final KyouErr EmptySchemaItemName = new KyouErr();

        public static final KyouErr AddNullAsChild = new KyouErr();
        public static final KyouErr AddDocumentAsChild = new KyouErr();
        public static final KyouErr AddSelfAsChild = new KyouErr();
        public static final KyouErr AddParentAsChild = new KyouErr();

        public static final KyouErr ForEachFail = new KyouErr();

        public static final KyouErr InvalidSchemaBuilderArguments = new KyouErr();

        /**
         * 对{@link DataDocument}进行操作时发生的异常
         */
        public static class Data {
            public static final KyouErr PathNotExist = new KyouErr();
            public static final KyouErr PathNotEditable = new KyouErr();
            public static final KyouErr RequireArrayPath = new KyouErr();
            public static final KyouErr RequireArrayElementPath = new KyouErr();
            public static final KyouErr RequireNotArrayElementPath = new KyouErr();
        }

        /**
         * {@link DPath}语法错误或进行{@link DPath}操作时发生的异常
         */
        public static class Path {
            public static final KyouErr DPathSyntaxError = new KyouErr();
            public static final KyouErr DPathSegmentSyntaxError = new KyouErr();
            public static final KyouErr DPathMustStartWithRoot = new KyouErr();
            public static final KyouErr DPathRootCannotHaveIndex = new KyouErr();
        }

        /**
         * {@link DQuery}语法错误或进行{@link DQuery}操作时发生的异常
         */
        public static class Query {
            public static final KyouErr NullDQuery = new KyouErr();
            public static final KyouErr UnsupportedAction = new KyouErr();
        }
    }

    /**
     * 进行序列化/反序列化操作时发生的异常
     */
    public static class Seriallize {
        public static final KyouErr NullSchemaToSerialize = new KyouErr();
        public static final KyouErr NullDataToSerialize = new KyouErr();

        public static final KyouErr XmlSerializeSchemaFail = new KyouErr();
        public static final KyouErr XmlSerializeDataFail = new KyouErr();
        public static final KyouErr XmlDeserializeSchemaFail = new KyouErr();
        public static final KyouErr XmlDeserializeDataFail = new KyouErr();

        public static final KyouErr InvalidSchemaXmlTag = new KyouErr();
        public static final KyouErr InvalidDataXmlTag = new KyouErr();
        public static final KyouErr InvalidDataLevel = new KyouErr();
    }

    /**
     * {@link StyleSpecification}中的语法或语义错误
     */
    public static class Style {
        public static final KyouErr SpecifcationSyntaxError = new KyouErr();

        public static final KyouErr KyouStringSyntaxError = new KyouErr();
        public static final KyouErr KyouHexStringSyntaxError = new KyouErr();

        public static final KyouErr InitSegmentFail = new KyouErr();
        public static final KyouErr InvalidSegmentTag = new KyouErr();
        public static final KyouErr InvalidSegmentParam = new KyouErr();

        public static final KyouErr InvalidParamResultType = new KyouErr();

        public static final KyouErr InitParamFail = new KyouErr();
        public static final KyouErr NullParamExpr = new KyouErr();
        public static final KyouErr InvalidParamTag = new KyouErr();
        public static final KyouErr ParamShouldUnary = new KyouErr();
        public static final KyouErr ParamShouldBinary = new KyouErr();
        public static final KyouErr InvalidParamPostfix = new KyouErr();

        public static final KyouErr ParamPostfixRequired = new KyouErr();
        public static final KyouErr ParamPostfixNotRequired = new KyouErr();
        public static final KyouErr ParamPostfixRequiresPositiveInteger = new KyouErr();

        public static final KyouErr DQuerySyntaxError = new KyouErr();
        public static final KyouErr EmptyDQuerySegment = new KyouErr();

        public static final KyouErr InvalidRefId = new KyouErr();

    }

    /**
     * 进行组包相关操作时发生的异常
     */
    public static class Pack {
        public static final KyouErr NullSchema = new KyouErr();
        public static final KyouErr NullData = new KyouErr();
        public static final KyouErr NullSpecifcation = new KyouErr();

        public static final KyouErr PackFail = new KyouErr();

        public static final KyouErr NoStyleUnitSuitable = new KyouErr();

        public static final KyouErr ParseStringToIntFail = new KyouErr();

        public static final KyouErr RequireSchemaStruct = new KyouErr();
        public static final KyouErr RequireSchemaField = new KyouErr();
        public static final KyouErr RequireSchemaArray = new KyouErr();
        public static final KyouErr RequireSchemaNotArray = new KyouErr();
        public static final KyouErr RequireSchemaStructArray = new KyouErr();
        public static final KyouErr RequireSchemaFieldArray = new KyouErr();

        public static final KyouErr FieldNotFound = new KyouErr();

    }
}
